package com.lzm.ydpt.mvp.presenterimpl;

import com.byt.framlib.basemvp.BasePresenter;
import com.byt.framlib.basemvp.basebean.BaseResponseBean;
import com.byt.framlib.basemvp.exception.ApiException;
import com.byt.framlib.basemvp.listener.OnLoadingErrorListener;
import com.byt.framlib.basemvp.listener.OnLoadingProgressListener;
import com.lzm.ydpt.entity.mall.ProductBean;
import com.lzm.ydpt.module.mall.activity.ProductHistoryActivity;
import com.lzm.ydpt.mvp.api.ProgressSubscriber;
import com.lzm.ydpt.mvp.contract.ProductHistoryContract;
import com.lzm.ydpt.mvp.modelimpl.ProductHistoryModelImpl;

import java.util.List;

import okhttp3.RequestBody;

/**
 * 类名称：ProductHistoryPresenterImpl
 * 类描述：代理实现
 */
public class ProductHistoryPresenterImpl extends BasePresenter implements ProductHistoryContract.Presenter {

    private ProductHistoryContract.View mView;
    private ProductHistoryContract.Model mModel;

    public ProductHistoryPresenterImpl(ProductHistoryActivity context) {
        super(context);
        this.mView = context;
        this.mModel = new ProductHistoryModelImpl();
    }

    @Override
    public void onProductHistory(RequestBody requestBody) {
        mManager.http(mModel.onProductHistory(requestBody), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<List<ProductBean>>() {
            @Override
            public void onLoadingResult(BaseResponseBean<List<ProductBean>> entity) {
                mView.onProductHistory(entity.getData());
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showMessage(e.getDisplayMessage(), method);
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showMessage(entity.getMessage(), method);
            }
        }, "onProductHistory"));
    }
}